/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canvas;

import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import midlet.MidletPlay;
import util.WrapText;

/**
 * @author LTTDNQ
 */
public class MIDPCanvasHowToPlay extends GameCanvas implements CommandListener {
    private Command _cmExit;
    private Graphics graphics;
    private MidletPlay midlet;
    private int _chieudai = getWidth();
    private int _chieucao = getHeight();
    private Image imgBg;
    private String txtHD = "Nhiệm vụ của bạn là hứng các quả trứng rớt xuống. Di chuyển rổ bằng các phím trái/phải"
             + "Dùng các phím 4/6/8 để có thể thêm gà/vịt/ngan. Mỗi lần bạn không hứng được trứng hoặc là hứng nhầm "
             + "phân. Thì bạn sẽ bị mất một mạng. Khi không còn số mạng thì bạn sẽ thua cuộc";
    /**
     * constructor
     */
    public MIDPCanvasHowToPlay(MidletPlay midlet) {
        super(false);
        this.midlet = midlet;
        graphics = this.getGraphics();
        try {
            _cmExit =  new Command("Exit", Command.EXIT, 1);
            // Set up this canvas to listen to command events
            setCommandListener(this);
            // Add the Exit command
            
            addCommand(_cmExit);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * paint
     */
    public void paintHowToPlay() {
        try {
            imgBg = Image.createImage("/Images/imgBackground.png");
            graphics.drawImage(imgBg, 0, 0, Graphics.LEFT | Graphics.TOP);
            Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
            WrapText wrap = new WrapText(graphics, txtHD,_chieudai*2/10, _chieucao*4/10, _chieudai*6/10, font, Graphics.LEFT);
            wrap.write();
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    /**
     * Called when a key is pressed.
     */
    protected void keyPressed(int keyCode) {
    }

    /**
     * Called when a key is released.
     */
    protected void keyReleased(int keyCode) {
    }

    /**
     * Called when a key is repeated (held down).
     */
    protected void keyRepeated(int keyCode) {
    }

    /**
     * Called when the pointer is dragged.
     */
    protected void pointerDragged(int x, int y) {
    }

    /**
     * Called when the pointer is pressed.
     */
    protected void pointerPressed(int x, int y) {
    }

    /**
     * Called when the pointer is released.
     */
    protected void pointerReleased(int x, int y) {
    }

    /**
     * Called when action should be handled
     */
    public void commandAction(Command command, Displayable displayable) {
        if(command == _cmExit){
            midlet.vaoManHinhMenu();
        }
    }
}
